package com.qf.map;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import com.qf.set.Book;

public class HashMapTest01 {
	
	public static void main(String[] args) {
		
		HashMap<Integer,Book> hashMap = new HashMap<Integer,Book>();
		
		
		hashMap.put(1, new Book(101,"《巨人现金》","富勒",59.5));
		hashMap.put(2,new Book(103,"《史记》","司马光",118.2));
		hashMap.put(3,new Book(104,"《原则》","瑞达利欧",68.4));
		hashMap.put(4,new Book(106,"《箐英》","罗伯特·清崎",45.8));
		hashMap.put(5,new Book(105,"《价值》","张磊",125.8));
		hashMap.put(6,new Book(102,"《Java进阶》","马士兵",15.5));
		
	
		
		//hashMap遍历
		//System.out.println(hashMap);
		
		Set<Integer> keySet = hashMap.keySet();
		//1.遍历方法，先获取map里所有key的值，并存放在set里，然后根据set里的key去找value
		for (Integer i : keySet) {
			System.out.println(hashMap.get(i));
		}
		
		Set<Entry<Integer, Book>> entrySet = hashMap.entrySet();
		
		//2.获取整个entry(就相当于key和value的结合)，根据entry再输出key和value
		for (Entry<Integer, Book> entry : entrySet) {
		
			System.out.println(entry.getKey()+"  "+entry.getValue());
		}
		
		
		
	}

}
